email me at borlaj@portlandschools.org

Loading
notes previous (11/<11) submit the dump links  
 

Opening/saving images (only in Applications):

You can easily open (or save) a png, gif or jpg and add it to your program. You MIGHT use a filechooser to select the file or save it.

Opening
   
            JFileChooser chooser = new JFileChooser();
            chooser.showOpenDialog(this);
            int returnVal = chooser.showSaveDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                File file = chooser.getSelectedFile();
                try{
                    Image   img = ImageIO.read(file);                  
                    g.drawImage(img, 0, 55, this); 
                }
                catch (Exception e){}
            }
Saving (if you have a layer called layerSet - you need to be using buffergraphics for this to work)
   
            JFileChooser chooser = new JFileChooser();
            int returnVal = chooser.showSaveDialog(this);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                try {
                    File file = chooser.getSelectedFile();                    
                    ImageIO.write(layerSet, "png", file);
                }
                catch(IOException ioe)
                {
                    System.out.println("Clip write help: " + ioe.getMessage());
                }
            }

Have these imports:

import java.io.*;
import javax.imageio.ImageIO;